<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>new的原理</title>
</head>
<body>
    <script>
        function create(){
            // 定义一个空对象
            let obj = {};
            // 取出参数列表中的第一个参数 (构造函数)
            let Con = [].shift.call(arguments);
            // 链接原型
            obj.__proto__ = Con.prototype;
            // 改变this指向,传入剩余参数;
            let result = Con.apply(obj,arguments);
            // ?? 
            return result instanceof Object ? result : obj ;
        };
        
        function Person (name,age){
            console.log(this);
            this.name = name;
            this.age = age;
        };
        console.log(Person);                                                                              
        /* let p1 = create(Person,'nikco',231);
        console.log(p1);
        console.log(Person.prototype);
        console.log(Person.__proto__.__proto__) */
        
    </script>
</body>
</html>